package cn.woblog.recyclerviewsample;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import cn.woblog.recyclerviewsample.HeaderFooterActivity1.Data;

/**
 * Created by renpingqing on 2017/4/4.
 */

public class HeaderFooterCustomAdapter extends
    BaseRecyclerViewAdapter<Data, HeaderFooterCustomAdapter.ViewHolder> {

  public HeaderFooterCustomAdapter(Context context) {
    super(context);
  }

  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new ViewHolder(getInflater().inflate(R.layout.simple_list_item_header, parent, false));
  }

  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    Data data = getData(position);
    holder.bindData(data);

    holder.itemView.getLayoutParams().height = data.getHeight();
  }

  class ViewHolder extends BaseRecyclerViewAdapter.ViewHolder {

    private final TextView tv;

    public ViewHolder(View itemView) {
      super(itemView);
      tv = (TextView) itemView.findViewById(android.R.id.text1);
    }

    public void bindData(Data data) {
      tv.setText(data.getString());
    }
  }
}
